package com.zhuangfei.hpuhelper.ui;

import java.util.List;

import com.zhuangfei.hpuhelper.bean.PhoneBean;

import cn.lzf.serviceplatform.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ResultAdapter extends BaseAdapter {

	Context context;
	
	LayoutInflater inflater;
	
	List<PhoneBean> datas;
	
	public void setDatas(List<PhoneBean> datas) {
		this.datas = datas;
	}
	
	public ResultAdapter(Context context,List<PhoneBean> datas) {
		this.context=context;
		this.datas=datas;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return (datas!=null?datas.size():0);
	}

	@Override
	public Object getItem(int arg0) {
		return (datas!=null?datas.get(arg0):null);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.item_phone_result_layout, null);
			holder=new ViewHolder();
			holder.tel=(TextView) convertView.findViewById(R.id.id_result_item_tel);
			holder.office=(TextView) convertView.findViewById(R.id.id_result_item_office);
			convertView.setTag(holder);
		}else holder=(ViewHolder) convertView.getTag();
		 
       
        PhoneBean  bean=datas.get(position);
       holder.office.setText(bean.getOffice());
       holder.tel.setText(bean.getPhone());
		return convertView;
	}
	
	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
		Log.e("size",datas.size()+"");
	}

	class ViewHolder{
		TextView tel;
		TextView office;
	}
}
